<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
    export default {
        mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.Edit],
        components: {
            SelectImage: async () => Vue.extend(await Vue.prototype.$vFN.Components.Base.SelectImage()),
            SelectDataGoods: async () => Vue.extend(await Vue.prototype.$vFN.Components.Base.SelectDataGoods()),
        },
        data() {
            return {
                appWindow: window,
                form: {
                    // 等级名称
                    name: "",
                    // 等级权重
                    level_weight: null,
                    // 超越奖比例
                    transcend_ratio: "",
                    // 分红比例
                    deduct_ratio: "",
                    // 感恩奖比例
                    grade_ratio: "",
                    // 育人奖比例
                    educate_ratio: "",
                    // 平级奖比例
                    equal_ratio: "",
                    // 等级说明
                    level_describe_status: 1,
                    // 等级说明（内容）:为空不显示
                    level_describe: "",
                    // 业绩奖励
                    achievements: [],
                    // 升级方式
                    upgrade_method: 1,
                    // 指定购买商品
                    buy_specified_product: [],
                    // 自购订单总额
                    self_order_amount: 0,
                    // 自购订单总数
                    self_order_number: 0,
                    // 团队经销商人数
                    team_dealer_number: 0,
                    // 团队总人数
                    team_member_number: 0,
                    // 团队订单总数
                    team_order_number: 0,
                    // 团队交易总额
                    team_trade_amount: 0,
                    // 提现总额
                    withdraw_amount: 0,
                    upgrade_show_array: [1],
                },
                
                // 页面接口地址
                apiUrl: {
                    create: "plugin/team-dividend/admin/level/addLevel",
                    update: "plugin/team-dividend/admin/level/editLevel",
                    detail: "plugin/team-dividend/admin/level/levelDetail",
                },
                loading: true,
                // 全部等级
                levelList: [1,2,3,4,5,6,7,8,9,10],
                // 不能选等级
                noLevel: [],
                // 升级方式
                conditionList: [
                    "指定购买商品",
                    "自购订单总额",
                    "自购订单总数",
                    "团队经销商人数",
                    "团队总人数",
                    "团队订单总数",
                    "团队交易总额",
                    "提现总额"
                ],
                
            };
        },
        methods: {
            // 业绩区间
            addAchievements() {
                this.form.achievements.push({
                    section: "",
                    award: ""
                })
            },
            delAchievements(item, index) {
                this.$delete(this.form.achievements, index);
            },
            // 获取不能选等级
            async getLevel() {
                let res = await this.$vFN.Http.post({
                    url: "plugin/team-dividend/admin/level/notSelectWeight",
                },window);
                this.noLevel = res.data;
                // console.log(this.noLevel);
            },
            // 选择等级权重
            addLevel(item,index) {
                this.form.level_weight = item;
            },
            
            select(item, index) {
                if(!this.form.upgrade_show_array.includes(index)) {
                    this.form.upgrade_show_array.push(index);
                }
            },
            del(_id, name) {
                let arr = []
                this.form.upgrade_show_array.forEach(item => {
                    if(item != _id) {
                        arr.push(item)
                    }
                })
                this.form.upgrade_show_array = arr;

                switch(name) {
                    case 'buy_specified_product':
                        this.form.buy_specified_product = [];
                        break;
                    case 'self_order_amount':
                        this.form.self_order_amount = 0;
                        break;
                    case 'self_order_number':
                        this.form.self_order_number = 0;
                        break;
                    case 'team_dealer_number':
                        this.form.team_dealer_number = 0;
                        break;
                    case 'team_member_number':
                        this.form.team_member_number = 0;
                        break;
                    case 'team_order_number':
                        this.form.team_order_number = 0;
                        break;
                    case 'team_trade_amount':
                        this.form.team_trade_amount = 0;
                        break;
                    case 'withdraw_amount':
                        this.form.withdraw_amount = 0;
                        break;
                }
            },

            // form 提交添加/修改 的参数扩展方法
            mixinEdit_editFormSubmitExtend(data_) { 
                
                return data_;
            },
            // 编辑修改的参数扩展方法
            mixinEdit_editDataExtend(data_) {
                // 添加
                if (this.mixinEdit_editType == "add") {
                    
                }
                // 修改
                else if (this.mixinEdit_editType == "update") {
                    if(data_.upgrade_show_array == null) {
                        data_.upgrade_show_array = [];
                    }
                }
                // 复制
                else if (this.mixinEdit_editType == "copy") {
                    
                }

                return data_;
            },
            

            // 初始化
            async init() {
                this.getLevel();
                // 初始化数据
                await this.mixinEdit_editBoxInit({
                    model: "form",
                    id: this.id,
                });
            },


        },
        mounted() {
            this.init();
        },
        activated() {},
    };
</script>